<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组排序</title>
  <script>
    // 17.数组排序；[3,4,1,2,6,5] ---> [1,2,3,4,5,6]
    function work17(x) {
      //数组排序
      x.sort(function (a, b) {
        if (a < b) {
          return -1;
        } else if (a > b) {
          return 1;
        } else {
          return 0;
        }
      })
      //返回数组
      return x;
    }
    //调用函数
    console.log(work17([3, 4, 1, 2, 6, 5]));
  </script>
</head>

<body>

</body>

</html>